+2005-08-14 Øyvind Kolås <pippin@gimp.org>
+
+ * tests/float_to_u8.c
+ * tests/u8_to_float.c
+ * tests/grayscale_to_rgb.c: new files
+ * tests/Makefile.am: including preceding tests
+
2005-08-14 Øyvind Kolås <pippin@gimp.org>
* babl/Makefile.am: added babl-instance.h, removed wilcard from
+TESTS = \
+ float_to_u8 \
+ grayscale_to_rgb \
+ u8_to_float
+
+float_to_u8_SOURCES = float_to_u8.c
+u8_to_float_SOURCES = u8_to_float.c
+grayscale_to_rgb_SOURCES = grayscale_to_rgb.c
+
+
+AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
+LDADD = $(top_builddir)/babl/libbabl.la -lm
+
+
noinst_PROGRAMS = \
introspect \
- nop
-
-AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
+ nop \
+ $(TESTS)
-introspect_SOURCES = \
- introspect.c
-introspect_LDADD = $(top_builddir)/babl/libbabl.la
+introspect_SOURCES = introspect.c
+nop_SOURCES = nop.c
-nop_SOURCES = \
- nop.c
-nop_LDADD = $(top_builddir)/babl/libbabl.la
-EXTRA_DIST= \
- .cvsignore
+EXTRA_DIST = .cvsignore
-TESTS=nop introspect
--- /dev/null
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "babl.h"
+#include "babl-internal.h"
+
+#define BUFFER_LENGTH 6
+
+float float_buf[BUFFER_LENGTH]=
+{
+ 0.0,
+ 1.0,
+ -1.0,
+ 2.0,
+ 0.5,
+ 0.25,
+};
+
+unsigned char u8_buf [BUFFER_LENGTH];
+unsigned char u8_ref_buf [BUFFER_LENGTH]=
+{
+ 0,
+ 255,
+ 0,
+ 255,
+ 127,
+ 63,
+};
+
+int
+test_float_to_rgb_u8 (void)
+{
+ BablFish *fish;
+ int i;
+ int OK=1;
+
+
+ fish = babl_fish (
+ (Babl*) babl_pixel_format_new (
+ "foo",
+ babl_model ("grayscale"),
+ babl_type ("float"),
+ babl_component ("luminance"),
+ NULL
+ ),
+ (Babl*) babl_pixel_format_new (
+ "bar",
+ babl_model ("grayscale"),
+ babl_type ("u8"),
+ babl_component ("luminance"),
+ NULL
+ ));
+
+ babl_fish_process (fish,
+ float_buf, u8_buf,
+ BUFFER_LENGTH);
+
+ for (i=0; i<BUFFER_LENGTH; i++)
+ {
+ if (u8_buf[i] != u8_ref_buf[i])
+ OK=0;
+ }
+ if (!OK)
+ return -1;
+ return 0;
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ babl_init ();
+ if (test_float_to_rgb_u8 ())
+ return -1;
+ babl_destroy ();
+ return 0;
+}
+
+
+
--- /dev/null
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "babl.h"
+#include "babl-internal.h"
+
+#define PIXELS 5
+
+float grayscale_buf [PIXELS]= {-0.1, 0.0, 0.4, 1.0, 2.0};
+
+float rgb_buf_ref [PIXELS*3]=
+{ -0.1, -0.1, -0.1, 0.0, 0.0, 0.0, 0.4, 0.4, 0.4, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
+
+float rgb_buf [PIXELS*3];
+
+int
+test (void)
+{
+ BablFish *fish;
+ int i;
+ int OK=1;
+
+
+ fish = babl_fish (
+ (Babl*) babl_pixel_format_new (
+ "foo",
+ babl_model ("grayscale"),
+ babl_type ("float"),
+ babl_component ("luminance"),
+ NULL
+ ),
+ (Babl*) babl_pixel_format_new (
+ "bar",
+ babl_model ("rgb"),
+ babl_type ("float"),
+ babl_component ("red"),
+ babl_component ("green"),
+ babl_component ("blue"),
+ NULL
+ ));
+
+ babl_fish_process (fish,
+ grayscale_buf, rgb_buf,
+ PIXELS);
+
+ for (i=0; i<PIXELS * 3; i++)
+ {
+ if (rgb_buf[i] != rgb_buf_ref[i])
+ {
+ babl_log ("index %i is problematic", i);
+ OK=0;
+ }
+ }
+ if (!OK)
+ return -1;
+ return 0;
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ babl_init ();
+ if (test())
+ return -1;
+ babl_destroy ();
+ return 0;
+}
+
+
+
--- /dev/null
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "babl.h"
+#include <math.h>
+#include "babl-internal.h"
+
+#define BUFFER_LENGTH 4
+#define TOLERANCE 0.003
+
+unsigned char u8_buf [BUFFER_LENGTH]= { 0, 255, 127, 63, };
+float float_ref_buf[BUFFER_LENGTH] = { 0.0, 1.0, 0.5, 0.25, };
+float float_buf [BUFFER_LENGTH];
+
+int
+test (void)
+{
+ BablFish *fish;
+ int i;
+ int OK=1;
+
+
+ fish = babl_fish (
+ (Babl*) babl_pixel_format_new (
+ "foo",
+ babl_model ("grayscale"),
+ babl_type ("u8"),
+ babl_component ("luminance"),
+ NULL
+ ),
+ (Babl*) babl_pixel_format_new (
+ "bar",
+ babl_model ("grayscale"),
+ babl_type ("float"),
+ babl_component ("luminance"),
+ NULL
+ ));
+
+ babl_fish_process (fish,
+ u8_buf, float_buf,
+ BUFFER_LENGTH);
+
+ for (i=0; i<BUFFER_LENGTH; i++)
+ {
+ if (fabs (float_buf[i] - float_ref_buf[i]) > TOLERANCE)
+ {
+ babl_log ("%i .. %f-%f=%f",
+ u8_buf[i], float_buf[i], float_ref_buf[i],
+ fabs (float_buf[i] - float_ref_buf[i])
+ );
+ OK=0;
+ }
+ }
+ if (!OK)
+ return -1;
+ return 0;
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ babl_init ();
+ if (test())
+ return -1;
+ babl_destroy ();
+ return 0;
+}
+
+
+